<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined( '_JEXEC' ) or die( 'Restricted access' );

class iJoomla_SurveysControllerNewsurvey extends iJoomla_SurveysController{
	
	function __construct() {	  
		parent::__construct();
		// Register Extra tasks		
		$this->registerTask('', 'edit');
		$this->registerTask('save', 'save');
		$this->registerTask('apply', 'apply');
		$this->registerTask('cancel', 'cancel');		
	}			
	
	function edit(){	
		JRequest::setVar( 'view', 'Newsurvey' );	
		parent::display();
	}
		
	function apply(){
		$model = $this->getModel('newsurvey');
		$response = $model->save();		
		$link = "index.php?option=com_surveys&controller=newsurvey&id=".$response["1"];		
		if ($response["0"] === false) {
			$msg = JText::_("COM_SURVEYS_SURVEY_SAVE_UNSUCCESSFULLY");
			$this->setRedirect($link, $msg, 'notice');
		} 
		elseif($response["0"] === true) {
		 	$msg = JText::_("COM_SURVEYS_SURVEY_SAVE_SUCCESSFULLY");		
			$this->setRedirect($link, $msg);
		}
	}
	
	function save(){
		$model = $this->getModel('newsurvey');
		$response = $model->save();		
		$link = "index.php?option=com_surveys&controller=surveys";		
		if ($response["0"] === false) {
			$msg = JText::_("COM_SURVEYS_SURVEY_SAVE_UNSUCCESSFULLY");
			$this->setRedirect($link, $msg, 'notice');
		} 
		elseif($response["0"] === true) {
		 	$msg = JText::_("COM_SURVEYS_SURVEY_SAVE_SUCCESSFULLY");		
			$this->setRedirect($link, $msg);
		}
	}
	
	function cancel(){
		$msg = JText::_("COM_SURVEYS_OPERATION_CANCELED");
		$link = "index.php?option=com_surveys&controller=surveys";		
		$this->setRedirect($link, $msg);
	}
}

?>